package com.bwt.usermanage;

import android.annotation.SuppressLint;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import com.lljjcoder.Interface.OnCityItemClickListener;
import com.lljjcoder.bean.CityBean;
import com.lljjcoder.bean.DistrictBean;
import com.lljjcoder.bean.ProvinceBean;
import com.lljjcoder.citywheel.CityConfig;
import com.lljjcoder.style.citypickerview.CityPickerView;

public class TestActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);
        showCityPicker();
    }

    public void showCityPicker(){

        final CityPickerView cityPicker=new CityPickerView();
        cityPicker.init(this);
        CityConfig cityConfig = new CityConfig.Builder()
                .province("浙江省")//默认显示的省份
                .city("杭州市")//默认显示省份下面的城市
                .district("余杭区")//默认显示省市下面的区县数据
                .build();
        cityPicker.setConfig(cityConfig);

        final EditText editCity=findViewById(R.id.edit_city);

        //点击监听
        editCity.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                cityPicker.setOnCityItemClickListener(new OnCityItemClickListener() {
                    @SuppressLint("SetTextI18n")
                    @Override
                    //点击确定
                    public void onSelected(ProvinceBean province, CityBean city, DistrictBean district) {
                        Toast.makeText(TestActivity.this,province+" - "+city+" - "+district,Toast.LENGTH_LONG).show();
                        editCity.setText(province+" - "+city+" - "+district);
                    }
                    @Override
                    //点击取消
                    public void onCancel() {
                    }
                });
                cityPicker.showCityPicker();
            }
        });
    }
}